#[derive(Debug)]
struct User {
    username: String
}

fn study_print() {
    println!("Hello, world!");
    // 测试打印
    // {} 作为占位符
    println!("hello world! - {}", "first");
    // {:o} 打印8进制
    println!("打印16进制 - 小写 - {:o}", 16);
    // {:x} 打印16进制 - 小写
    println!("hello world! - {:x}", 255);
    // {:X} 打印16进制 - 大写
    println!("打印16进制 - 大写 - {:X}", 255);
    // 打印指针
    let str1 = "hello world!";
    println!("打印指针 - {:p}", &str1);
    // 二进制
    println!("打印二进制 - {:b}", 255);
    
    println!("{:?}", str1);
    let user = User{
        username: String::from("yangxuan")
    };
    // 不加 #[derive(Debug)] 注解就会报错。
    // 会以一种 Debug 打印信息
    println!("{:?}", user);
    println!("{:#?}", user);

    // 名字占位符
    println!("名字占位符 - {username}, {password}", username = user.username, password = &user.username);
    // 下标占位符
    println!("下标占位符 - {0}, {3}, {2}, {1}", 1, 2, 3, 4);
    // -- 其他输出打印 格式 详参 https://doc.rust-lang.org/std/fmt/index.html
}

fn var_data_type_study() {
    let v = "yangxuan";
    println!("不可变-变量 - {}", v);
    // 编译报错
    // cannot assign twice to immutable variable
    // v = "moda";

    // 使用 mut 修饰 - 就变为可变变量
    // 另外使用了变量遮盖的特性
    // 何为变量遮盖？变量遮盖的意思就是，我在这个地方创建了一个相同名字的变量。
    // 而非将变量重新做赋值！
    let mut v = 100;
    println!("可变-变量 - {}", v);

    // 改变 变量的值
    v = 200;
    println!("改变变量的值 - {}", v);

    // 数据类型 
    let v: i32 = 8;
    println!("32位整形 - {}", v);
    let big_int: i32 = std::i32::MAX;
    println!("32位整形最大值 - {}", big_int);

    let big_f32: f32 = std::f32::MAX;
    println!("32浮点数最大值 - {}", big_f32);

    // bool 类型
    let b: bool = false;
    // 其实可以转为整形
    assert_eq!(b as i32, 0);
    assert_eq!(true as i32, 1);
    // 会出现断言报错
    // assert_eq!(true as i32, 0);

    // 元组
    let tuple1 = (1, "yangxuan", 18, true);
    println!("info --- {}, {}, {}, {}", tuple1.0, tuple1.1, tuple1.2, tuple1.3);
    let (id, name, age, is_married) = tuple1;
    println!("info --- {}, {}, {}, {}", id, name, age, is_married);

    // 数组
    let arr1 = [0, 9, 8, 7, 6, 5];
    println!("arr1 - {:?}", arr1);
    println!("arr1 - {}, {}, {}, {}, {}, {}", arr1[0], arr1[1], arr1[2], arr1[3], arr1[4], arr1[5]);
    println!("arr1-len - {}", arr1.len());
    let arr2: [bool;6] = [true, false, true, false, true, false];

    // Vector
    let mut vec1 = vec![1, 2, 3];
    println!("vector - {:?}", vec1);
    vec1.push(4);
    vec1.push(5);
    vec1.push(6);
    vec1.pop();
    println!("vector - {:?}", vec1);
    let mut vec2 = Vec::<i32>::new();
}

fn main() {
    study_print();
    var_data_type_study();
}

